home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / changebar / chbar.sh (.txt) < prev   
LaTeX Document  |  1994-04-18  |  3KB  |  85 lines

  1. ******************************* snip snip ****************************
  2. #! /bin/sh
  3. #    Gadget to take two LaTeX files and produce a third which
  4. #    has changebars highlighting the difference between them.
  5. # Version 1.1
  6. # Author:
  7. #    Don Ward, Careful Computing (don@careful.co.uk)
  8. # v1.0    April 1989
  9. # v1.1  Feb 93    Amended to use changebar.sty (v3.0) and dvips
  10. # Useage:
  11. #    chbar file1 file2 [output]
  12. #        (default output is stdout)
  13. #    chbar old
  14. #        (new file on stdin, output on stdout)
  15. # Method:
  16. # 1    Use diff to get an ed script to go from file1 to file2.
  17. # 2    Breath on it a bit (with sed) to insert changebar commands.
  18. # 3    Apply modified ed script to produce (nearly) the output.
  19. # 4    Use awk to insert the changebars option into the \documentstyle
  20. #    and to handle changebar commands inside verbatim environments.
  21. # 5     Remove changebars before \begin{document} with sed
  22. if test $# -eq 0
  23. then cat <<\xEOF
  24. Useage:
  25.     chbars old new [output]
  26.     chbars old
  27. exit 0
  28. #    Strictly speaking, should check that $TMP doesn't exist already.
  29. TMP=/tmp/chb-$$
  30. export TMP
  31. OLD=$1
  32. if test $# -eq 1
  33. then   NEW="-";     # arg is old file, take new from stdin
  34. else   NEW=$2 ; 
  35. #    sed commands to edit ed commands to edit old file
  36. cat <<\xEOF > $TMP
  37. /^\.$/i\
  38. \\cbend{}%
  39. /^[0-9][0-9]*[ac]$/a\
  40. \\cbstart{}%
  41. /^[0-9][0-9]*,[0-9][0-9]*[ac]$/a\
  42. \\cbstart{}%
  43. /^[0-9][0-9]*d$/a\
  44. \\cbdelete{}%\
  45. /^[0-9][0-9]*,[0-9][0-9]*d$/a\
  46. \\cbdelete{}%\
  47. diff -b -e $OLD $NEW | ( sed -f $TMP ; echo w ${TMP}1 ; echo q ) | ed - $OLD
  48. #    awk commands to insert Changebars style and to protect
  49. #    changebar commands in verbatim environments
  50. #       and to tell what driver is in use
  51. cat <<\xEOF >$TMP
  52. /^\\documentstyle/{
  53.   if (index($0, "changebar") == 0 ) {
  54.     opts = index($0, "[")
  55.     if (opts > 0)
  56.     printf "%schangebar,%s",substr($0,1,opts),substr($0,opts+1)
  57.     else
  58.     printf "\\documentstyle[changebar]%s\n", substr($0,15)
  59.     next
  60. /\\begin{document}/ {print "\\driver{dvips}"}
  61. /\\begin{verbatim}/{++nesting}
  62. /\\end{verbatim}/{--nesting}
  63. /\\cbstart{}%|\\cbend{}%|\cbdelete{}%/ {
  64.   if ( nesting > 0) {
  65. #    changebar command in a verbatim environment: Temporarily exit,
  66. #    do the changebar command and reenter.
  67. #    The obvious ( printf "\\end{verbatim}%s\\begin{verbatim} , $0 )
  68. #    leaves too much vertical space around the changed line(s).
  69. #    The following magic seeems to work
  70.     print  "\\end{verbatim}\\nointerlineskip"
  71.     print  "\\vskip -\\ht\\strutbox\\vskip -\\ht\\strutbox"
  72.     printf "\\vbox to 0pt{\\vskip \\ht\\strutbox%s\\vss}\n", $0
  73.     print  "\\begin{verbatim}"
  74.     next
  75. { print $0 }
  76. awk -f $TMP ${TMP}1 >${TMP}2
  77. #    sed commands to clean up unwanted changebars
  78. #    (those before \begin{document})
  79. cat <<xEOF >$TMP
  80. 1,/\\begin{document}/s/\\\\cb[sed][tne][adl][^{}]*{}%$/%/
  81. if test $# -le 2 || test $3 = '-'
  82. then  sed -f $TMP ${TMP}2
  83. else  sed -f $TMP ${TMP}2 >$3
  84. rm $TMP ${TMP}[0-9]
  85.